#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
int init_val = 100;
int uninit_val;
int g_val = 100;
int main(int argc ,char** argv,char** env) {
    pid_t id = fork();

    if(id == 0){
        //子进程
        int cnt = 5;
        while(1){
            printf("chind pid : %d ppid: %d id : %d g_val : %d &g_val : %p\n",getpid(),getppid(),id,g_val,&g_val);
            sleep(1);
            cnt--;
            if(cnt == 0){
                g_val = 200;
                printf("g_val = 100 ---> g_val = 200\n");
            }
        }   
    }
    else{
        while(1){
            printf("father pid : %d ppid : %d id : %d g_val : %d &g_val = %p\n",getpid(),getppid(),id,g_val,&g_val);
            sleep(1);
        }
    }

   // const char* str = "hello linux";
   // char * ch = (char*)malloc(1);
   // printf("code addr : %p\n",main);
   // printf("read only char addr : %p\n",str);
   // printf("init global value addr : %p\n",&init_val);
   // printf("uninit global value addr : %p\n",&uninit_val);
   // printf("heap addr : %p\n",ch);
   // printf("stack addr : %p\n",&str);
   // 
   // char * ch1 = (char*)malloc(1);
   // char * ch2 = (char*)malloc(1);
   // char * ch3 = (char*)malloc(1);
   // char * ch4 = (char*)malloc(1);
   // char * ch5 = (char*)malloc(1);
   // printf("heap1 addr : %p\n",ch1);
   // printf("heap2 addr : %p\n",ch2);
   // printf("heap3 addr : %p\n",ch3);
   // printf("heap4 addr : %p\n",ch4);
   // printf("heap5 addr : %p\n",ch5);

   // printf("stack addr : %p\n",&ch1);
   // printf("stack addr : %p\n",&ch2);
   // printf("stack addr : %p\n",&ch3);
   // printf("stack addr : %p\n",&ch4);
   // printf("stack addr : %p\n",&ch5);
   // 
   // int i = 0;
   // for(;argv[i];i++){
   //     printf("argv[%d] : %p\n",i,argv[i]);
   // }
   // for(i = 0;env[i];i++){
   //     printf("env[%d] ； %p\n",i,env[i]);
   // }
    return 0;
}
